package com.leetcode.LC;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LC15 {
    public static void main(String[] args) {

        List<List<Integer>> lists = new LC15().threeSum(new int[]{-4,-8,7,13,10,1,-14,-13,0,8,6,-13,-5,-4,-12,2,-11,7,-5,0,-9,-14,-8,-9,2,-7,-13,-3,13,9,-14,-6,8,1,14,-5,-13,8,-10,-5,1,11,-11,3,14,-8,-10,-12,6,-8,-5,13,-15,2,11,-5,10,6,-1,1,0,0,2,-7,8,-6,3,3,-13,8,5,-5,-3,9,5,-4,-14,11,-8,7,10,-6,-3,11,12,-14,-9,-1,7,5,-15,14,12,-5,-8,-2,4,2,-14,-2,-12,6,8,0,0,-2,3,-7,-14,2,7,12,12,12,0,9,13,-2,-15,-3,10,-14,-4,7,-12,3,-10});
        for (List<Integer> list : lists) {
            System.out.println(list);

        }

    }

    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> arrayLists = new ArrayList<List<Integer>>();
        for (int x = 0; x < nums.length - 2; x++) {
            for (int y = x + 1; y < nums.length; y++) {
                for (int z = y + 1; z < nums.length; z++) {
                    if (nums[x] + nums[y] + nums[z] == 0) {
                        if (!arrayLists.contains(Arrays.asList(nums[x], nums[y], nums[z]))
                                && !arrayLists.contains(Arrays.asList(nums[x], nums[z], nums[y]))
                                && !arrayLists.contains(Arrays.asList(nums[y], nums[x], nums[z]))
                                && !arrayLists.contains(Arrays.asList(nums[y], nums[z], nums[x]))
                                && !arrayLists.contains(Arrays.asList(nums[z], nums[x], nums[y]))
                                && !arrayLists.contains(Arrays.asList(nums[z], nums[y], nums[x]))
                        ) {
                            arrayLists.add(Arrays.asList(nums[x], nums[y], nums[z]));
                        }
                    }
                }
            }
        }

        return arrayLists;
    }
}
